const mongoose = require('mongoose')


// 创建集合模型
const userSchema = new mongoose.Schema({
    username: {
        type: String,
        required: true,
        minlength: 2,
        maxlength: 20
    },
    email: {
        type: String,
        // 保证邮箱地址不重复
        required: true
    },
    password: {
        type: String,
        required: true
    },
    avatar: {
        type: String
    },
    date: {
        type: Date,
        default: new Date()
    },
    role: {
        type: String
    }
});

const User = mongoose.model('User', userSchema);

module.exports = User



// async function createUser() {
//     const salt = await bcrypt.genSalt(10);
//     const pass = await bcrypt.hash('123456', salt);
//     const user = await User.create({
//         username: 'chengge',
//         email: 'chengge@nsd.cn',
//         password: pass,
//         role: 'admin',
//         state: 0
//     });
// }

// createUser();